package com.auth.manage.auth.controller.user;

import com.auth.manage.web.vo.Result;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("token")
public class TokenController {
    private static final String TOKEN_PREFIX = "token:";

    private final StringRedisTemplate redisTemplate;

    @GetMapping("/get")
    public Result<String> get(@NotBlank String scene){
        String token = UUID.randomUUID().toString();
        String tokenKey = TOKEN_PREFIX + scene + ":" + token;
        redisTemplate.opsForValue().set(tokenKey, token, 30, TimeUnit.MINUTES);
        return Result.success(tokenKey);
    }
}
